﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Gtkj.CMS.App.Models
{
    public class SessionHelp
    {
        /// <summary>
        /// 取得des解密后的字符串
        /// </summary>
        /// <param name="enPwd"></param>
        /// <returns></returns>
        public static string  GetDeCode(string enPwd)
        {
            string key = "";
            if (System.Web.HttpContext.Current.Session["TempKey"] != null)
            {
                key = System.Web.HttpContext.Current.Session["TempKey"].ToString();
            }
            else
            {
                return null;
            }

            string result = Common.DesCrypt.DesDecrypt(key, enPwd);
            return Common.StringHelper.SubStringEnd(result);
        }
        /// <summary>
        /// 删除密钥
        /// </summary>
        public static void DeleteCryptKey()
        {
            System.Web.HttpContext.Current.Session["TempKey"] = null;
        }


        /// <summary>
        /// 取得一个密钥key
        /// </summary>
        /// <returns></returns>
        public static string GetCryptKey()
        {
            string key = Guid.NewGuid().ToString("N");
            System.Web.HttpContext.Current.Session["TempKey"] = key;
            return key;
        }
    }
}